home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / doc / sigprc11 < prev    next >
Text File  |  1997-07-08  |  2KB  |  49 lines

  1. ; This batch file creates a plot a bandstop filter which suppresses
  2. ; frequencies between 7 cycles per second and 15 cycles per second for
  3. ; data sampled every 0.02 seconds, using the Hanning window. It is used
  4. ; in Chapter 13, "Signal Processing", of _Using IDL_.
  5.  
  6. delt = 0.02 ; sampling period in seconds
  7.  
  8. f_low = 15. ; frequencies above f_low will be passed
  9.  
  10. f_high = 7. ; frequencies below f_high will be passed
  11.  
  12. nfilt = 81 ; the length of the filter
  13.  
  14. f_filt = FINDGEN(nfilt/2+1) / (nfilt*delt)
  15.  
  16. ideal_fr = (f_filt GT f_low) $ ; pass frequencies greater than f_low
  17.         OR (f_filt LT F_high)  ; pass frequencies less than f_high
  18.  
  19. ideal_fr = FLOAT(ideal_fr) ; convert from byte to floating point
  20.  
  21. ; replicate to obtain values for negative frequencies:
  22.  
  23. ideal_fr = [ideal_fr, REVERSE(ideal_fr(1:*))]
  24.  
  25. ; now use an inverse FFT to get the impulse response of the ideal filter
  26.  
  27. ideal_ir = FLOAT(FFT(ideal_fr, /INVERSE)) ; ideal_fr is an even function,
  28.                                           ; so the result is real
  29. ideal_ir = ideal_ir / nfilt ; scale by the # of points
  30.  
  31. ideal_ir = SHIFT(ideal_ir, nfilt/2) ; shift it before applying the window
  32.  
  33. ; apply a Hanning window to the shifted ideal impulse response
  34.  
  35. bs_ir_n = ideal_ir*HANNING(nfilt) ; these are the coefficients of the filter
  36.  
  37. ; The frequency response of the filter is the FFT of its impulse response: 
  38.  
  39. bs_fr_n = FFT(bs_ir_n) * nfilt ; scale by the number of points
  40.  
  41. ; log plot of magnitude in dB
  42.  
  43. mag = ABS(bs_fr_n(0:nfilt/2)) ; mag of Hanning bandstop filter x'fer f'n
  44.  
  45. PLOT, f_filt, 20*ALOG10(mag), YTITLE='Magnitude in dB', $
  46.     XTITLE='Frequency in cycles / second', /XLOG, $
  47.     XRANGE=[1.0,1.0/(2.0*delt)], XSTYLE=1, $
  48.     TITLE='Frequency Response for Bandstop!CFIR Filter (Hanning)'
  49.